package com.sbtr.common.calculate;

import cn.hutool.json.JSONUtil;
import com.sbtr.common.enums.DataTypeEnum;
import com.sbtr.common.file.dto.FileContentDto;
import com.sbtr.common.interfaces.CalculateAnalysis;
import com.sbtr.common.util.DataObjectConvertUtil;
import com.sbtr.exception.BDException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;

@Component
public class CalculateAnalysisReflectUtil {
    public final static List<Class<?>> annotatedClasses = new ArrayList<>();
    public CalculateAnalysisReflectUtil() {
        annotatedClasses.add(DataAnalysisUtil.class);
    }
    public static void main(String[] args) throws InvocationTargetException, IllegalAccessException {
        new CalculateAnalysisReflectUtil();
        List<String> data = new ArrayList<>();
        data.add("3.5");
        data.add("4.3");
        data.add("6.7");
        data.add("2.5");
        data.add("8.0");
        data.add("9.2");
        data.add("1.2");
        data.add("5.5");
        for (Class<?> ann:annotatedClasses) {
            for (Method method:ann.getMethods()) {
                if(method.getName().equals("duaByVar")){
                    CalculateAnalysis calculateAnalysis = method.getAnnotation(CalculateAnalysis.class);
                    Object r = DataObjectConvertUtil.convert(data, DataTypeEnum.FLOAT2.getCode());
                    Object transformedData =  method.invoke(new DataAnalysisUtil(),r);
                    System.out.println(JSONUtil.toJsonStr(transformedData));
                }
            }
        }
    }


//    public Object execDataAnalysis(String methodName,List<String>... data) throws InvocationTargetException, IllegalAccessException {
//        for (Class<?> ann: CalculateAnalysisReflectUtil.annotatedClasses) {
//            for (Method method:ann.getMethods()) {
//                if(method.getName().equals(methodName)){
//                    CalculateAnalysis calculateAnalysis = method.getAnnotation(CalculateAnalysis.class);
//                    Object r = DataObjectConvertUtil.convert(data,calculateAnalysis.in().getCode());
//                    return method.invoke(new DataAnalysisUtil(),r);
//                }
//            }
//        }
//        return null;
//    }

}
